<template>
  <Card :loading="loading" title="本月总效率" class="md:w-1/3 !md:my-0 !my-10px w-full">
    <div ref="chartRef" :style="{ width, height }"></div>
  </Card>
</template>
<script lang="ts" setup>
  import { Ref, ref, watch } from 'vue';
  import { Card } from 'ant-design-vue';
  import { useECharts } from '/@/hooks/web/useECharts';
  const props = defineProps({
    loading: Boolean,
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: '110px',
    },
  });
  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  watch(
    () => props.loading,
    () => {
      if (props.loading) {
        return;
      }
      setOptions({
        tooltip: {
          trigger: 'item',
        },
        series: [
          {
            color: ['#5ab1ef','#eeeeee'],
            name: '本月总效率',
            type: 'pie',
            radius: ['90%','70%'],
            avoidLabelOverlap: false,
            label: {
              show: true,
              position: 'center',
            },
            labelLine: {
              show: false,
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '12',
                fontWeight: 'bold',
              },
            },

            data: [
              { value: 77, name: '77%' },
              { value: 23, name: '23%' },
            ],
          },
        ],
      });
    },
    { immediate: true },
  );
</script>
